package com.it.selfAfter.controller;

import com.it.selfAfter.entity.PrizeInfo;
import com.it.selfAfter.service.PrizeInfoService;
import com.it.selfAfter.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 抽奖相关接口,提供抽奖信息的增删改查功能
 * @Author: Coke
 * @DateTime: 2023/05/20/18:11
 **/

@CrossOrigin(origins = "*") // 解决跨域问题
@RestController
@RequestMapping ("/api/prizeInfo")
@Slf4j
@Api (tags = "抽奖相关接口,提供抽奖信息的增删改查功能")
public class PrizeInfoController {
    
    @Autowired
    private PrizeInfoService prizeInfoService;
    
    /**
     * 根据手机号更新抽奖信息
     * @DateTime: 2023/6/13 23:18
     *
     * @param prizeInfo:  用户手机号
     * @return Result<?>
     * @author: Coke
     */
    @ApiOperation (value = "根据手机号更新抽奖信息", notes = "根据手机号更新抽奖信息")
    @PostMapping ("/updateInfo")
    private Result<?> updatePrizeInfo(@ApiParam (value = "用户手机号", readOnly = true) @RequestBody PrizeInfo prizeInfo){
        return Result.success(prizeInfoService.updatePrizeInfo(prizeInfo.getPhone(), prizeInfo.getCount()));
    }
    
    /**
     * 根据手机号获取抽奖信息
     * @DateTime: 2023/6/13 23:18
     *
     * @param prizeInfo:  用户手机号
     * @return Result<?>
     * @author: Coke
     */
    @ApiOperation (value = "根据手机号获取抽奖信息", notes = "根据手机号获取抽奖信息")
    @PostMapping ("/getInfo")
    private Result<?> getPrizeInfo(@ApiParam (value = "用户手机号", readOnly = true) @RequestBody PrizeInfo prizeInfo){
        return Result.success(prizeInfoService.getPrizeInfo(prizeInfo.getPhone()));
//        return userService.updateQuote(phone, quote);
    }
}
